//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __PSEUDO_H__
#define __PSEUDO_H__

#include <elasys_server.h>

_ELASTOS_NAMESPACE_USING

class CPseudoKernel
{
public:
    STATIC CARAPI System_GetTime(
        /* [out] */ SystemTime *pSystemTime);

    STATIC CARAPI System_SetTime(
        /* [in] */ SystemTime * pSystemTime);

    STATIC CARAPI System_GetElapsedTime(
        /* [out] */ Millisecond32 * pTime);

    STATIC CARAPI System_QueryPerformanceCounter(
        /* [out] */ Int64 * pCounter);

    STATIC CARAPI System_QueryPerformanceFrequency(
        /* [out] */ Int64 * pFrequency);

    STATIC CARAPI System_GetIdleTime(
        /* [out] */ Millisecond32 * pTime);

    STATIC CARAPI System_Reboot();

    STATIC CARAPI System_GetAllProcesses(
        /* [out] */ IObjectEnumerator ** ppProcesses);

    STATIC CARAPI System_GetMemorySizes(
        /* [out] */ Int32 * pTotalPhysicalMemorySize,
        /* [out] */ Int32 * pAvailablePhysicalMemorySize);

    STATIC CARAPI System_GetDomainHostManager(
        /* [out] */ IHostingManager ** ppHostingManager);

    STATIC CARAPI System_TryWaitForAnyEvent(
        /* [in] */ const BufferOf<IEvent *> * pEvents,
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult * pResult,
        /* [out] */ Int32 * pIndex,
        /* [out] */ EventState * pState);

    STATIC CARAPI System_RequestIntrestedEvent(
        /* [in] */ SystemEvents intrestedEvents,
        /* [out] */ IEvent ** ppEvent);

    STATIC CARAPI System_GetEnvironMutex(
        /* [out] */ IMutex ** ppEnvMutex);

    STATIC CARAPI System_DebugPrint(
        /* [in]  */ const wchar_t * str);

    STATIC CARAPI System_DebugErrorPrint(
        /* [in]  */ const wchar_t * wstr);

    //------------------------------------------
    STATIC CARAPI Process_CreateWithUnstarted(
        /* [out] */ IProcess ** ppProcess);

    STATIC CARAPI_(IProcess *) Process_GetCurrent();

    STATIC CARAPI_(ProcessId) Process_GetCurrentId();

    STATIC CARAPI_(void) Process_ExitCurrent(
        /* [in] */ ExitCode exitCode);

    STATIC CARAPI Process_LoadModule(
        /* [in] */ WString name,
        /* [in] */ ModuleLoadFlags flags,
        /* [out] */ IModule ** ppModule);

    STATIC CARAPI Process_FlushInstructionCache(
        /* [in] */ Address basAddr,
        /* [in] */ MemorySize size);

    //------------------------------------------
    STATIC CARAPI Thread_Create(
        /* [in] */ Address entry,
        /* [in] */ Address userEntry,
        /* [in] */ Address userArgs,
        /* [in] */ ThreadCreationFlags flags,
        /* [out] */ IThread ** ppThread);

    STATIC CARAPI_(IThread *) Thread_GetCurrent();

    STATIC CARAPI_(ThreadId) Thread_GetCurrentId();

    STATIC CARAPI_(Boolean) Thread_CurrentIsMain();

    STATIC CARAPI_(void) Thread_QuitCurrent(
        /* [in] */ QuitCode quitCode);

    STATIC CARAPI Thread_Sleep(
        /* [in] */ Millisecond32 msTimeout,
        /* [out] */ WaitResult * pResult);

    STATIC CARAPI Thread_Yield();

    //------------------------------------------
    STATIC CARAPI  VirtualMemory_Map(
        /* [in] */ Address vBaseAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ MemoryProtection protect,
        /* [out] */ Address *pBaseAddr);

    STATIC CARAPI VirtualMemory_Query(
        /* [in] */ Address vAddress,
        /* [out] */ Address *pBaseAddr,
        /* [out] */ MemorySize *pSize);

    STATIC CARAPI VirtualMemory_SetProtection(
        /* [in] */ Address vBaseAddr,
        /* [in] */ MemorySize size,
        /* [in] */ MemoryProtection protect);

    STATIC CARAPI VirtualMemory_CheckProtection(
        /* [in] */ Address vAddress,
        /* [in] */ MemoryProtection protect,
        /* [out] */ Boolean *pIsValid);

    STATIC CARAPI VirtualMemory_Commit(
        /* [in] */ Address vAddress);

    STATIC CARAPI VirtualMemory_IoRemap(
        /* [in] */ Address virtualAddr,
        /* [in] */ MemorySize size,
        /* [in] */ Address physicalAddr,
        /* [in] */ MemoryMapFlags flags,
        /* [in] */ MemoryProtection protect,
        /* [out] */ Address *pVirtualAddr);

    STATIC CARAPI VirtualMemory_Unmap(
        /* [in] */ Address vBaseAddr,
        /* [in] */ MemorySize size);

    //------------------------------------------
    STATIC CARAPI Mutex_Create(
        /* [out] */ IMutex ** ppMutex);

    STATIC CARAPI Mutex_Create(
        /* [in] */ WString name,
        /* [out] */ IMutex ** ppMutex,
        /* [out] */ Boolean * pbAlreadyExisted);

    STATIC CARAPI Event_Create(
        /* [in] */ Boolean bManualReset,
        /* [in] */ EventState initState,
        /* [out] */ IEvent ** ppEvent);

    STATIC CARAPI Event_Create(
        /* [in] */ WString name,
        /* [in] */ Boolean bManualReset,
        /* [in] */ EventState initState,
        /* [out] */ IEvent ** ppEvent,
        /* [out] */ Boolean * pbAlreadyExisted);

    STATIC CARAPI Condition_Create(
        /* [out] */ ICondition ** ppCondition);

    STATIC CARAPI Condition_Create(
        /* [in] */ WString name,
        /* [out] */ ICondition ** ppCondition,
        /* [out] */ Boolean * pbAlreadyExisted);

    STATIC CARAPI ReaderWriterLock_Create(
        /* [out] */ IReaderWriterLock ** ppRwlock);

    STATIC CARAPI ReaderWriterLock_Create(
        /* [in] */ WString name,
        /* [out] */ IReaderWriterLock ** ppRwlock,
        /* [out] */ Boolean * pbAlreadyExisted);

    STATIC CARAPI SharedMemory_Create(
        /* [in] */ WString name,
        /* [in] */ MemorySize memorySize,
        /* [in] */ Boolean bCommit,
        /* [out] */ ISharedMemory ** ppSharedMemory,
        /* [out] */ Boolean * pbAlreadyExisted);

    //------------------------------------------
    STATIC CARAPI Tls_AcquireSlot(
        /* [in] */ ThreadLocalSlotType type,
        /* [out] */ Int32 * pSlotIndex);

    STATIC CARAPI Tls_RelinquishSlot(
        /* [in] */ Int32 slotIndex,
        /* [out] */ BufferOf<Int32> * pUsedPtrs);

    STATIC CARAPI Tls_CleanupSlot(
        /* [in] */ Int32 slotIndex,
        /* [out] */ BufferOf<Int32> * pUsedPtrs);

    STATIC CARAPI Tls_GetValue(
        /* [in] */ ThreadLocalSlotType type,
        /* [in] */ Int32 slotIndex,
        /* [out] */ PVoid * ppValue);

    STATIC CARAPI Tls_SetValue(
        /* [in] */ ThreadLocalSlotType type,
        /* [in] */ Int32 slotIndex,
        /* [in] */ PVoid pValue);

    //------------------------------------------
    STATIC CARAPI RegisterRunningObject(
        /* [in] */ WString name,
        /* [in] */ PInterface pObject);

    STATIC CARAPI FindRunningObject(
        /* [in] */ WString name,
        /* [out] */ PInterface *ppObject);

    STATIC CARAPI WaitForRunningObject(
        /* [in] */ WString name,
        /* [in] */ Int32 timeout,
        /* [out] */ WaitResult *pResult);

    STATIC CARAPI UnregisterRunningObject(
        /* [in] */ WString name);
};

#endif // __PSEUDO_H__

